/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ucjava.chat.socialnetworking.userinterface;

import com.ucjava.chat.commserve.rmi.common.User;
import java.rmi.RemoteException;
import javax.swing.JOptionPane;

/**
 *
 * @author adunagan
 */
public class NewUser {

    static int counter = 0;

    // method creates new User object
    public void addUser() throws RemoteException {

        // begin counter for failed attempts
        for (int i = counter; i < 3; i++) {
            // create User object
            // 'placeHolder' is being used during development
            User placeHolder = new User();

            // prompt for username, if blank then prompt again. 
            String newUser = JOptionPane.showInputDialog("Please enter new user's name.");
            while (newUser == null) {
                JOptionPane.showMessageDialog(null, "Please enter valid username");
                counter = counter++;
                // loop
                if (counter < 3) {
                    addUser();
                } else {
                    // throws error after too many failed attempts;
                    if (counter == 4) {
                        JOptionPane.showMessageDialog(null, "Too many failed attempts");
                    }
                }
            }

            // set User's name
            placeHolder.setUserName(newUser);

        }
    }
}